<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use App\Models\Notice;

class NoticeController extends Controller
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function list(Request $request)
    {
        $perPage = $request->input('size', 10); // 每页条数，默认10条
        $notices = Notice::query()
            ->where('status', Notice::STATUS_SHOW) // 只查询显示的公告
            ->orderByDesc('is_top') // 按置顶排序
            ->orderByDesc('created_at') // 按创建时间排序
            ->paginate($perPage);

        return $this->success([
            'list' => $notices->items(),
            'total' => $notices->total(),
        ]);
    }
}
